<#--<#include "../layout/base.ftl">-->
<#--<#macro header>-->
<script type="text/javascript">
    $(function () {
        $("#bl_search_panel").omPanel({
            title: "高级搜索"
        });


        $("#bl_status").omCombo({
            width: 100,
            dataSource: [
                {text: '未导入', value: '1'},
                {text: '导入成功', value: '3'},
                {text: '删除成功', value: '5'},
                {text: '导入失败', value: '2'},
                {text: '删除失败', value: '4'}
            ],
            value: '1',
            editable: false
        });


        $('span#bl_button_search').omButton({
            width: 70,
            icons: {left: '${base}/css/default/images/advanced/search.png'},
            onClick: function (event) {
                var url = "${base}/bank_loan/grid_json?status=" + $("#bl_status").omCombo('value')
                        + "&voucherNum=" + $("#bl_voucher_num").val();
                $('#bl_grid').omGrid("setData", encodeURI(url));
            }
        });

        var url = "${base}/bank_loan/grid_json?status=" + $("#bl_status").omCombo('value')
                + "&voucherNum=" + $("#bl_voucher_num").val();

        var grid = $('#bl_grid').omGrid({
            dataSource: encodeURI(url),
            height: 370,
            width: 'fit',
            autoFit: true,
            limit: 10,
            //单据号码 收款日期 收款类型 客户名称 收款金额 票据号码 入帐银行 类型 审核人 公司名称
            colModel: [
                {header: '类型', name: 'type', align: 'left'},
                {header: '日期', name: 'time', align: 'left'},
                {header: '银行名称', name: 'bankName', align: 'left'},
                {header: '金额', name: 'money', align: 'left'},
                {header: '备注', name: 'remark', align: 'left'},
                {header: '制单人', name: 'operator', align: 'left'},
                {header: '凭证号', name: 'voucher', align: 'left'},
                {header: '公司名称', name: 'company', align: 'left'},
                {header: '操作', name: 'imported', align: 'center', renderer: function (colValue, rowData, rowIndex) {
                    if (colValue == "add")
                        return '<button onClick="blShowDialog(' + rowData.id + ',' + rowData.xxtype + ')">导入</button>';
                    if (colValue == "delete")
                        return '<button onClick="blRevokeVoucher(' + rowData.id + ',' + rowData.xxtype + ')">删除凭证</button>';
                    if (colValue == "reset")
                        return '<button onClick="">重置</button>';
                    return '';
                }}
            ]
        });

        $(window).scroll(function () {
            $("#bl_grid").omGrid('resize');
        });

        $("#bl_dialog").omDialog({
            title: "导入凭证",
            autoOpen: false,
            resizable: true,
            modal: true,
            width: 800,
            buttons: [
                {
                    text: "确定",
                    click: function () {
                        $.post('${base}/bank_loan/generate_voucher_json',
                                {'id': $("#bl_id").val(), 'attachment': $("#bl_attachment").val()},
                                function (data) {
                                    $('span#bl_button_search').omButton("click");
                                    $("#bl_dialog").omDialog("close");
                                    var type = data.responseflag == "1" ? "success" : "error";
                                    $.omMessageBox.alert({
                                        type: type,
                                        title: '提示',
                                        content: data.responsemessage
                                    });
                                }, "json");
                    }
                },
                {
                    text: "取消",
                    click: function () {
                        $("#bl_dialog").omDialog("close");
                    }
                }
            ]
        });
    });

    var bl_item_table_row = '<tr><td width="13%" style="padding: 0px"><input type="text" style="width:100px" value=":digest"/></td>' +
            '<td width="13%" align="left">:subjectname</td>' +
            '<td width="13%" align="right">:debit</td>' +
            '<td width="13%" align="right">:credit</td>' +
            '<td width="13%">:departmentname</td>' +
            '<td width="13%"></td></tr>';

    function blShowDialog(id, xxtype) {
        var data = {"id": id, "xxtype": xxtype};
        $("#bl_id").val(id);
        $.post("${base}/bank_loan/voucher_json", data, function (data, textStatus, jqXHR) {

            $("#bl_typecode").html(data.voucher.master.vchrtypecode);
            $("#bl_createuser").html(data.voucher.master.createuser);
            $("#bl_createdate").val(data.voucher.master.systemdate);
            $("#bl_createdate").omCalendar({
                editable: false
            });

            $("#bl_items").html("");
            if (data.voucher.items.length != 0) {
                var items_table = "";
                for (var i = 0; i < data.voucher.items.length; i++) {
                    var item = data.voucher.items[i];
                    var temp = bl_item_table_row.replace(":digest", item.digest);
                    temp = temp.replace(":subjectname", item.subjectname);
                    temp = temp.replace(":debit", item.debit);
                    temp = temp.replace(":credit", item.credit);

                    if (item.isdept == 0)
                        temp = temp.replace(":departmentname", "");
                    else
                        temp = temp.replace(":departmentname", '<select style="width:100px"><option></option></select>');

//                    if (item.isproc == 0)
//                        temp = temp.replace(":product", "");
//                    else
//                        temp = temp.replace(":product", '<input type="text" style="width:100px" class="itext" value="请双击选择项目" readonly/>');

                    items_table += temp;
                }
                $("#bl_items").html(items_table);
            }
            $("#bl_importType").omCombo({
                width: 138,
                dataSource: [
                    {text: '生成凭证号', value: '1'},
                    {text: '指定凭证号', value: '2'}
                ],
                value: '1',
                editable: false
            });
            $("#bl_dialog").omDialog('open');
        }, "json");
    }

    function ivRevokeVoucher(id) {
        $.omMessageBox.confirm({
            title: '提示',
            content: '是否确认撤销该凭证？',
            onClose: function (v) {
                if (v) {
                    var data = {"id": id, "xxtype": xxtype};
                    $.post("${base}/bank_loan/revoke_voucher_json", data,
                            function (data, textStatus, jqXHR) {
                                if (data.responseflag == "1") {
                                    $('span#bl_button_search').omButton("click");
                                }
                                var type = data.responseflag == "1" ? "success" : "error";
                                $.omMessageBox.alert({
                                    type: type,
                                    title: '提示',
                                    content: data.responsemessage
                                });
                            }, "json");
                }
            }
        });
    }
</script>
<#--</#macro>-->
<#--<#macro body>-->
<div id="bl_search_panel" class="search_panel">
    <div>
        <span class="label">状态：</span>
        <input id="bl_status"/>
        <span>凭证号：</span>
        <input id="bl_voucher_num" type="text" class="input-text"/>
        <span id="bl_button_search">搜索</span>
    </div>
</div>
<table id="bl_grid"></table>

<div id="bl_dialog">
    <form action='' method='post'>
        <input id="bl_id" type="hidden"/>
        <table width="100%">
            <tr>
                <td width="70px">字号</td>
                <td><span id="bl_typecode" style="font-size: 12px;font-weight: bold"></span></td>
                <td width="70px">制单人</td>
                <td id="bl_createuser">
                </td>
                <td width="70px">制单日期</td>
                <td>
                    <input id="bl_createdate" type="text" style="width: 120px"/>
                </td>
                <td width="70px">附单据数</td>
                <td>
                    <input id="bl_attachment" type="text" style="width: 120px"/>
                </td>
            </tr>
        </table>
        <br/>
        <table width="100%" class="form outtable">
            <thead>
            <tr>
                <th>摘要</th>
                <th>科目</th>
                <th>借方</th>
                <th>贷方</th>
                <th>部门</th>
                <th>项目</th>
            </tr>
            </thead>
            <tbody id="bl_items">
            </tbody>
        </table>
        <table width="100%">
            <tr>
                <td width="70px">导入方式</td>
                <td><input id="bl_importType"/></td>
                <td width="70px">凭证号</td>
                <td><input id="bl_voucherNumber" type="text" style="width: 118px"/></td>
            </tr>
        </table>
    </form>
</div>
<#--</#macro>-->